# delimit ;
clear ;
set more off ;
est drop _all ;
cd "R:/personlig/fenellac/menarche_replication/analysis/" ;

global plusdir "R:/personlig/fenellac/stata_ado/plus/" ;
sysdir set PLUS $plusdir ;
adopath ++ $plusdir ;

* **************************************************************************** ;
* This code replicates Table 2.
*
* Paper: "Age of Marriage and Women's Political Engagement: Evidence from India"
* Authors: Fenella Carpena, Francesca Jensenius
* 
* Code by Fenella Carpena
* Last update: March 3, 2020
* **************************************************************************** ;

****************************************************************************** ;
* select the sample
****************************************************************************** ;

use "./input/eligible-women-ihds02-lhs.dta", clear ;
merge 1:1 IDHH PERSONID using "./input/eligible-women-ihds02-rhs.dta" ;
tab _merge ;
assert _merge == 3 ;
drop _merge ;

* keep only rural women ;
keep if rural == 1 ;

* keep only women who are married only once (i.e., have not ever remarried) ;
drop if ever_remarried == 1 ;
  
* keep only women age of menarche between 11-18 (1st-99th pctile) ; 
summ menarche_age ;
keep if menarche_age >= 11 & menarche_age <= 18 ;

* generating district identifier ;
egen dt_id = group(STATEID DISTID) ;

****************************************************************************** ;
* label variables for the output table 
****************************************************************************** ;

* education ;
label var years_schooling "\shortstack[l]{Years \\ educ}" ;
label var can_read_write "\shortstack[l]{Can read\\ \& write}" ;
label var can_converse_english "\shortstack[l]{Can converse \\ in English}" ;
local educ "years_schooling can_read_write can_converse_english" ;

* number of children ;
label var num_children_with_resp "\shortstack[l]{Living w/ \\ respondent}" ;
label var num_children_tot "\shortstack[l]{Live \\ births} " ;
label var num_children_alive "\shortstack[l]{Total still \\ alive}" ;
local children "num_children_with_resp num_children_alive num_children_tot " ;

label var marriage_age "Marriage Age" ;

****************************************************************************** ;
* TABLE: IV regressions
****************************************************************************** ;
est drop _all ;

foreach var of varlist `educ' `children' { ;
 	ivreghdfe `var' height_measure hindu muslim sc st obc age mother_yrs_educ father_yrs_educ (marriage_age = menarche_age), a(dt_id) robust ;
	est sto `var' ;
	estadd local distFE "Yes" ;
} ;

esttab * using "./output/table-IV-educ-and-num-children.tex",
	replace
	drop(height_measure hindu muslim sc st obc age mother_yrs_educ father_yrs_educ) 
	cells(b(label() star fmt(%9.3f %9.3f)) se(par)) 
	star(* 0.10 ** 0.05 *** 0.01) 
	stats(N, fmt(%20s %9.0f) labels("Observations"))
	prehead(\begin{table}[h!]\centering \normalsize `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"'
		\captionsetup{justification=centering} 
		\caption{Effects of Marriage Age on Education and No. of Children, Rural Women \vspace{-2ex}}
		\label{table-IV-educ-and-num-children}
		\begin{tabular*}{0.95\hsize}{@{\hskip\tabcolsep\extracolsep\fill}l*{@E}{p{0.5cm}p{0.5cm}p{0.5cm}p{1.6cm}p{1.6cm}p{1.6cm}}}
		\toprule)
	legend label  booktabs  collabels( , none)
	mgroups(
	"\shortstack[c]{Education and Literacy}"
	"\shortstack[c]{Number of Children}"
	, pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	postfoot(`"\bottomrule"'  \end{tabular*} \captionsetup{justification=justified, width=0.95\hsize} 
		\caption*{\small \textit{Notes:} 
		IV regression, \textit{Marriage Age} instrumented with \textit{Menarche Age}.
		Data from IHDS 2011-12, rural women. 
		All regressions include district FEs, height, age, parents' education, caste, religion. 
		Robust SEs in parenthesis. ***\$\,p < 0.01$, **\$\,p < 0.05$, *\$\,p<0.10$.\looseness=-1}
		\end{table}) ;

exit ;

